#!usr/bin/env python
# -*- coding:utf-8 _*-
"""
@author:zhengxin
@file: permissions.py
@time: 2022/4/20  10:54
# @describe: 用户管理-权限
"""
from rest_framework.permissions import BasePermission, SAFE_METHODS


class IsSelOrRedOnly(BasePermission):
    """ 确保非安全方法只能由本人操作 """
    def has_object_permission(self, request, view, obj):
        if request.method in SAFE_METHODS:
            return True
        return obj == request.user
